<%@page import="java.rmi.RemoteException"%>
<%@page import="java.sql.SQLException"%>
<%@page import="clientData.MemberData"%>
<%@page import="clientData.MemberDataInt"%>
<%@page import="clientData.ForumData"%>
<%@page import="clientData.ForumDataInt"%>
<%@page import="clientData.TopicData"%>
<%@page import="clientData.TopicDataInt"%>
<%@page import="exception.NotLoggedInException"%>
<%@page import="java.util.Vector"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.rmi.Naming"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- this script is notifing the user about his friends -->

<script type="text/javascript" src="jquery.js"></script>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
<title>topics </title>
    <link href="styles.css" rel="stylesheet" type="text/css">
    <link href="tableDesign.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" type="text/JavaScript">
		<!--
		function MM_preloadImages() { //v3.0
		  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}
		-->
	</script>
</head>
	<%@ include file="serverConnection.jsp" %>
	<% 
		
		int forumId;
		if (request.getParameter("forumId")!=null)
		{
			forumId = Integer.parseInt(request.getParameter("forumId"));
			session.setAttribute("forumId",forumId);
		}
		else
			forumId = (Integer)session.getAttribute("forumId");	
		
		String forumName = request.getParameter("forumName");
			session.setAttribute("forumName",forumName);
		

		if (session.getAttribute("userName")==null)
		{
			response.sendRedirect("loggin.jsp");
			response.flushBuffer();
			return;
		}
		
		LinkedList<TopicDataInt> topics= null;
		
		try{
			topics = forum.getForumTopicList((String)session.getAttribute("userName"),(String)session.getAttribute("password"),forumId);
		}catch(NotLoggedInException t){
			response.sendRedirect("loggin.jsp");
			response.flushBuffer();
			return;	
		}
		catch(SQLException s){
			   
			   
			   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
				"SQL server is down");
			
				response.flushBuffer();
				return;
			   
			   
		   }
		   catch(RemoteException u){
			   
			   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
				"forum server is down");
			
				response.flushBuffer();
				return;
		   }
		
	%>
 <body link="#6C8EBD">
<div id="main"> 
	<div id="header">
		<div id="logo"><img src="Images/logo1.jpg" alt="logo" width="490" height="182"></div>
		<div id="picture"><img src="Images/logo2.jpg" alt="pic" width="289" height="156"></div>
	</div>
	<div id="line"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
    <div id="navigation">
		<% out.println(forumName+"'S TOPICS"); %>
	</div>
	<div id="line2"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
	<div id="text" ice:editable="*">
		<div id="bar">
			<div class="bluetxt" id="linktxt">
                  <p><a class="bluetxt" href="friends.jsp">manage friends</a> </p>
  				  <p><a class="bluetxt" href="addTopic.jsp?forumName=<%=forumName%>&forumId=<%=forumId%>">add Topic</a>  </p>
  	 			  <p><a class="bluetxt" href="mainScreen.jsp">main screen</a>  </p>
     			  <p><a class="bluetxt" href="index.jsp"  target="_top" onClick= "logoutFunc();">logout</a>  </p>
			</div>
		</div>
		<div id="text2">
			<div class="contentTXT" id="text2txt">

  
<%@ include file="scripts.jsp" %>
 
  
<table border="1" align="center">
	
	<thead>
	<tr>
		<th>NAME</th>
		<th>CREATOR</th>
		<th>CREATION TIME</th>
	</tr>
	</thead>
	<tbody>	
  	<%
  	
  for(TopicDataInt topic : topics){
  		out.println("<tr>");
  		out.println("<td><a href=posts.jsp?topicId="+topic.getId()+"&topicName="+ topic.getTitle().replace(" ","%20")+">" + topic.getTitle() +"</a></td>");
  		out.println("<td>" + topic.getCreator().getUserName() + "</td>");
  		out.println("<td>" + topic.getCreationTime()+ "</td>");
  		out.println("</tr>");
  }
  	
  	
  	%>
    
	</tbody>

</table>    
			</div>
		</div>
	</div>
<div id="Num"><img src="Images/line.jpg" alt="line" width="779" height="4"></div>
<div id="footer">
<div class="footerTXT" id="footertxt"><a class="footerTXT">Designed by ariel nir yuri gilad itzhaki and marina</a> </div>   </div>
</div>
</div>

</body>   

</html>